package com.touzbi.hss.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.touzbi.hss.beans.Soin;
import com.touzbi.hss.dao.AbstractDAOFactory;
import com.touzbi.hss.dao.AbstractSoinDAO;
import com.touzbi.hss.dao.DAOException;

public class SoinBO {

	private static final String CONTENT_PARAM = "content";
	private AbstractSoinDAO soinDAO;
	private String error = null;

	public SoinBO(AbstractDAOFactory daoFactory) {
		this.soinDAO = daoFactory.getSoinDAO();
	}

	private String getParameter(HttpServletRequest req, String paramName) {
		String param = req.getParameter(paramName);
		return param;
	}

	public Soin getSoin(HttpServletRequest req) {
		String content = getParameter(req, CONTENT_PARAM);
		Soin soin = new Soin();
		soin.setContent(content);
		return soin;
	}

	public List<Soin> getSoinList() {
		try {
			return this.soinDAO.getSoinList();
		} catch (DAOException e) {
			this.error = e.getMessage();
			return new ArrayList<Soin>();
		}
	}

	public void addSoin(HttpServletRequest req) {
		this.soinDAO.addSoin(getSoin(req));
	}

	public String getError() {
		return this.error;
	}

}
